<template>
  <div id="all">
    <div id="allItem">
      <div class="one" @click="addressManagement">
        <div v-if="jobs">
          <span>{{ jobs?.name }}</span>
          <span>{{ jobs?.mobile }}</span>
          <span> > </span>
        </div>
        <div v-if="jobs">{{ jobs?.district }}{{ jobs?.address }}</div>
        <div v-else>请选择地址</div>
      </div>

      <div class="job">
        <van-row align="center">
          <van-col span="14">
            <div class="profile">
              <div class="info">
                <div class="name">{{ curStudent.username }}</div>
                <div class="grade">{{ classFormat[curStudent.class] }}</div>
              </div>
              <div class="time">会员有效期：{{ curStudent.createtime }}</div>
            </div>
          </van-col>
          <van-col span="9"> </van-col>
        </van-row>
        <van-button
          type="primary"
          style="
            width: 100%;
            border-radius: 7px;
            background: none;
            border: solid 1px #ffc456;
            color: #ffc456;
            font-weight: bold;
            height: 35px;
            margin: 1rem 0;
          "
          @click="router.push('/StudentProfile')"
        >
          <van-icon name="plus" />
          添加</van-button
        >
      </div>

      <div class="three">
        <div>
          <img :src="curGiftJob?.image" alt="" />
        </div>
        <div style="display: flex; flex-direction: column; justify-content: space-around">
          <div
            style="
              overflow: hidden;
              text-overflow: ellipsis;
              display: -webkit-box;
              -webkit-line-clamp: 2;
              overflow: hidden;
              -webkit-box-orient: vertical;
            "
          >
            {{ curGiftJob?.title }}
          </div>
          <div>{{ curGiftJob?.class }}</div>
          <div>{{}}</div>
          <div>{{ curGiftJob?.money }}</div>
        </div>
      </div>

      <div class="four">
        <div>
          <span>商品金额</span>
          <span>￥{{ curGiftJob?.money }}</span>
        </div>
        <div @click="couponCenter">
          <span>优惠券</span>
          <span>暂无可用优惠券</span>
        </div>
        <div>
          <span>支付方式</span>
          <span>微信支付</span>
        </div>
        <div>
          <span></span>
          <span
            >实付款: <span>￥{{ curGiftJob?.money }}</span></span
          >
        </div>
      </div>
      <div class="five">
        <van-checkbox v-model="checked"></van-checkbox>
        <span @click="agree">我已阅读并同意</span>
        <span @click="apper"> 《支付协议》</span>
      </div>
    </div>
    <div class="six">
      <div>
        <span>总价:</span>
        <span>{{ curGiftJob?.money }}</span>
      </div>
      <div @click="giftOrders">立即支付</div>
    </div>
    <div class="seven" v-show="oj">
      <div>
        <div>支付协议</div>
        <div v-html="Fuck"></div>
        <div @click="clos">我已阅读并同意</div>
      </div>
      <div @click="clos">×</div>
    </div>
  </div>
</template>

<script setup>
import { useIntegrallist } from '@/stores/integralList.js' // 导入 useIntegrallist 函数，用于获取积分列表的 store
import { useUserInfoStore } from '@/stores/user.js' // 导入 useUserInfoStore 函数，用于获取用户信息的 store
import { storeToRefs } from 'pinia' // 导入 storeToRefs 函数，用于将 store 转换为响应式引用
import { showToast } from 'vant' // 导入 vant 库中的提示组件函数
import { ref } from 'vue' // 导入 Vue 的 ref 函数，用于创建响应式数据
import { useRouter, useRoute } from 'vue-router' // 导入 vue-router 库中的 useRouter 和 useRoute 函数，用于获取路由信息
import { addressIndex, giftBoxPayment } from '../api' // 导入自定义的 API 函数，用于地址和支付操作

const userInfoStore = useUserInfoStore() // 使用 useUserInfoStore 函数创建用户信息的 store 实例
const integrallist = useIntegrallist() // 使用 useIntegrallist 函数创建积分列表的 store 实例
const { curStudent, classFormat } = storeToRefs(userInfoStore) // 将 store 转换为响应式引用，并解构出相应的属性
const { curGiftJob } = storeToRefs(integrallist) // 将 store 转换为响应式引用，并解构出 curGiftJob 属性
const route = useRoute() // 获取当前路由信息
const orderId = route.query.orderId // 获取路由参数中的 orderId
const Fuck = route.query.Fuck // 获取路由参数中的 Fuck


const router = useRouter() // 创建一个 router 实例
const oj = ref(false) // 创建一个 ref 对象，默认为 false
const checked = ref(false) // 创建一个 ref 对象，默认为 false

// 模拟数据
const jobs = ref({}) // 创建一个 ref 对象，初始化为空对象
addressIndex({ user_id: curStudent?.value?.id }).then((res) => {
  jobs.value = res.find((item) => item.status == 1) // 将符合条件的地址信息赋值给 jobs
})
// --------------

// 支付协议弹窗关闭打开
const clos = () => {
  oj.value = false
}
const apper = () => {
  oj.value = true
}
// --------------------------

// 点击已阅读并同意，关闭弹窗，复选框选中
const agree = () => {}
// -----------------------------

// 优惠券挑转
function couponCenter() {
  router.push('/CouponCenter')
}
// 支付成功跳转
function giftOrders() {
  if (!checked.value) { // 判断复选框是否选中
    showToast(`请先同意支付协议`) // 显示提示消息，要求先同意支付协议
    return
  }
  giftBoxPayment({
    id: orderId,
    opayment_Amount: curGiftJob.value.money,
    status: 1
  }).then(() => {
    showToast({
      message: '支付成功',
      icon: 'https://pic.ntimg.cn/file/20170307/23639287_095616713000_2.jpg' // 使用在线图片链接充当支付成功提示
    })
    setTimeout(() => {
      router.push('/GiftOrders') // 2秒后跳转到 GiftOrders 页面
    }, 2000)
  })
}

// 点击地址跳转
function addressManagement() {
  router.push('/AddressManagement')
}

</script>

<style lang="less" scoped>
.profile {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: 2.5rem;
  box-sizing: border-box;
  .info {
    display: flex;
    align-items: center;
    .name {
      font-weight: bold;
      font-size: 16px;
    }
    .grade {
      font-size: 13px;
      background-color: #4ec183;
      display: grid;
      place-content: center;
      padding: 2px 0.5rem;
      border-radius: 10px;
      margin-left: 1rem;
      color: #ffffff;
    }
  }
  .time {
    font-size: 12px;
    color: #a3a3a3;
    font-weight: bold;
  }
}
.job {
  background-color: #ffffff;
  width: 100%;
  border-radius: 15px;
  padding: 0.7rem;
  margin: 1rem 0;
}

@var1: #f5f6f8;
@var2: #999999;
@var3: #fe6870;
@var4: #4ec183;
@var5: #969292;
@var6: #ffc456;
@var7: #9a9a9a;
@var8: #4b4747;
@var9: #717171;
@var10: #ffffff;
@var11: #fb4e4e;

#all {
  background-color: @var1;
  height: 95vh;
}
#allItem {
  width: 94%;
  margin-left: 3%;
  padding-top: 2vh;
}
.one {
  background-color: white;
  border-radius: 10px;
  padding: 1vh 2vw;
  > div:first-child {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    margin-bottom: 1vh;
    > span:last-child {
      width: 50%;
      display: flex;
      justify-content: end;
      color: @var2;
    }
  }
  > div:last-child {
    font-size: 14px;
  }
}
.two,
.three,
.four {
  background-color: white;
  border-radius: 10px;
  padding: 1vh 2vw;
  margin-top: 2vh;
}
.two > div:first-child {
  font-weight: 600;
  margin-bottom: 2vh;
}
#twoItem {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2vh;
  > div:first-child > div:first-child {
    font-size: 15px;
    margin-bottom: vh;
  }
  span {
    background-color: @var4;
    margin-left: 4vw;
    color: white;
    padding: 1% 1.5vw;
    border-radius: 10px;
    font-size: 11px;
  }
  > div:first-child > div:last-child {
    color: @var5;
    font-size: 13px;
  }
  ~ div {
    border: 1px solid @var6;
    padding: 0.5vh 0;
    font-size: 15px;
    border-radius: 5px;
    text-align: center;
    color: @var6;
    margin: 1vh 0;
  }
}
#cuo {
  background-color: @var3;
  width: 18px;
  height: 18px;
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.three img {
  width: 90px;
  height: 90px;
  border-radius: 10px;
  margin: 1vh 2vw;
}
.three > div:last-child {
  margin: 1vh 1vw;
  > div:first-child {
    font-size: 14px;
    font-weight: 600;
  }
  > div:nth-child(2),
  > div:nth-child(3) {
    font-size: 12px;
    margin-top: 0.7vh;
    color: @var7;
    font-weight: 600;
  }
  > div:last-child {
    font-size: 18px;
    font-weight: 600;
    margin-top: 0.7vh;
    &::before {
      content: '￥';
      font-size: 15px;
    }
  }
}
.three {
  display: flex;
}
.four > div {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  margin: 1.7vh 0;
  > span:first-child {
    font-weight: 600;
    color: @var8;
  }
  > span:last-child {
    color: @var9;
    > span {
      color: black;
      font-weight: 600;
      font-size: 16px;
    }
  }
  &:first-child > span:last-child {
    font-weight: 550;
  }
}
.five {
  margin-top: 2vh;
  padding-left: 1vw;
  display: flex;
  align-items: center;
  > span:nth-child(2) {
    margin-left: 1vw;
    font-size: 12px;
    color: rgb(99, 96, 96);
    font-weight: 600;
  }
  > span:last-child {
    color: @var6;
    font-size: 13px;
    font-weight: 600;
  }
}
.six {
  display: flex;
  justify-content: space-around;
  align-items: center;
  position: fixed;
  bottom: 3%;
  > div:last-child {
    background-color: @var6;
    width: 60vw;
    text-align: center;
    color: white;
    padding: 1.5vh 0;
    font-weight: 600;
  }
  > div:first-child {
    font-size: 15px;
    background-color: @var10;
    width: 40vw;
    padding: 1.5vh 0;
    text-align: center;
    > span:last-child {
      color: @var11;
      font-size: 19px;
      font-weight: 600;
      &::before {
        content: '￥';
        font-size: 15px;
      }
    }
  }
}
.seven {
  background-color: rgba(106, 107, 107, 0.5);
  position: absolute;
  top: 0;
  height: 100vh;
  width: 100vw;
  padding-top: 20vh;
  > div:first-child {
    width: 80%;
    margin-left: 10%;
    background-color: white;
    border-radius: 10px;
    padding-bottom: 3vh;
    > div:first-child {
      background-color: @var6;
      color: white;
      text-align: center;
      padding: 1vh 0;
      border-top-left-radius: 10px;
      border-top-right-radius: 10px;
    }
    > div:nth-child(2) {
      padding: 1.5vh 3vw;
    }
    > div:last-child {
      background-color: @var6;
      color: white;
      text-align: center;
      padding: 0.6vh 0;
      width: 60%;
      margin-left: 20%;
      border-radius: 5px;
      margin-top: 4vh;
      font-size: 14px;
    }
  }
  > div:last-child {
    border: 2px solid white;
    width: 25px;
    height: 25px;
    margin-left: 47%;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 2vh;
    font-size: 25px;
    border-radius: 50%;
    color: white;
  }
}
</style>
